package com.af.monitorModule.controller.monitor;

import com.af.monitorModule.generator.entity.Monitor;
import com.af.monitorModule.generator.entity.TimedTask;
import com.af.monitorModule.generator.service.MonitorService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/monitor")
public class MonitorController {

    @Autowired
    private MonitorService monitorService;

    @GetMapping("/findMonitor")
    public JSONObject findMonitor(String page,String limit,String search){
        return monitorService.findMonitor(page,limit,search);
    }

    @PostMapping("/changeState/{id}")
    public JSONObject changeState(@PathVariable String id){
        return monitorService.changeState(id);
    }

    @PostMapping("/batchChange")
    public JSONObject batchStop(@RequestBody JSONObject ids){
        return monitorService.batchStop(ids);
    }

    @PostMapping("/update/{id}")
    public JSONObject update(@RequestBody Monitor monitor, @PathVariable String id){
        return monitorService.updateMonitor(monitor,id);
    }

    @PostMapping("/add")
    public JSONObject add(@RequestBody Monitor monitor){
        return monitorService.add(monitor);
    }

    /**
     * 选项添加监控
     */
    @PostMapping("/switchAdd")
    @Transactional
    public JSONObject switchAdd(@RequestBody JSONObject monitors){
        return monitorService.switchAdd(monitors);
    }

    /**
     * 获取所有监控的名称
     */
    @GetMapping("/getAllName")
    public JSONObject getAllName(){
        return monitorService.getAllMonitorName();
    }
}
